package com.bonc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

import com.bonc.repo.EsRepositoryMarker;
import com.bonc.util.CmdAndShUtil;
/**
 * 信息检索，信息存入es；检索信息按空格分隔。
 * html显示；
 * @author litianlin
 * @date   2020年3月27日下午4:31:11
 * @Description TODO
 */
@SpringBootApplication
@EnableElasticsearchRepositories(basePackageClasses= {EsRepositoryMarker.class})
public class InfoAnalysisApplication {
	public static void main(String[] args) throws Exception {
		startEs();
		SpringApplication.run(InfoAnalysisApplication.class, args);
	}

	// 启动es
	private static void startEs() throws URISyntaxException, IOException, InterruptedException {
		// 判断ClassLoader，确定是否启动。appLoader、springboot-devtool loader都会加载本类
		ClassLoader loader = InfoAnalysisApplication.class.getClassLoader();
		boolean flag = loader.getClass().getName().startsWith("sun.misc.Launcher");
		// 启动es
//		if(flag){
//			System.out.println("start es");
//			String cmd = "D:\\workSoftware\\elasticsearch-5.6.16\\bin\\elasticsearch.bat";
//			CmdAndShUtil.runBatInWindow(cmd);
//			System.out.println("start es end");	
//			// 延长15s启动项目
//			TimeUnit.SECONDS.sleep(20);		
//		}
	}

}
